package com.hlw.hr_man.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.hlw.hr_man.service.EmployeeSrevice;
import com.hlw.hr_man.serviceImpl.EmployeeServiceImpl;

import net.sf.json.JSONObject;
/**
 * 权限分配中的找到所有员工
 * @author Administrator
 *
 */
public class FindEmployeecontroller extends HttpServlet {
	EmployeeSrevice employeeservice=new EmployeeServiceImpl();
      @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	doPost(req, resp);
    }
      @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	resp.setCharacterEncoding("utf8");
    	req.setCharacterEncoding("utf8");
    	PrintWriter pw=resp.getWriter();
    	JSONObject  employees  = new JSONObject();
      	    int page = Integer.parseInt(req.getParameter("page"));
    		int pageSize = Integer.parseInt(req.getParameter("rows"));
    		int start =  (page-1)*pageSize; 
    	if(req.getParameter("e_name")==null){
    	employees= employeeservice.getEmployees(start, pageSize);
    	pw.write(employees.toString());
    	}
    	else{
    		String e_name=req.getParameter("e_name");
    		employees=employeeservice.findAllEmployee(start, pageSize, e_name);
    		pw.write(employees.toString());
    	}
    }
}
